package com.yzf.wisecoder.wisecoderservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzf.wisecoder.wisecoderservice.service.ViewDatasourceService;
import com.yzf.wisecoder.wisecoderstorage.mysql.dao.ViewDatasourceDao;
import com.yzf.wisecoder.wisecoderstorage.mysql.entity.ViewConfigEntity;
import com.yzf.wisecoder.wisecoderstorage.mysql.entity.ViewDatasourceEntity;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author jianghuiyong
 * @email jianghuiyong@yunzhangfang.com
 * @date 2020-05-12 20:05:20
 */
@Service("viewDatasourceService")
public class ViewDatasourceServiceImpl extends ServiceImpl<ViewDatasourceDao, ViewDatasourceEntity> implements ViewDatasourceService {


    @Override
    public List<ViewDatasourceEntity> queryByDbId(Long dbId) {
        List<ViewDatasourceEntity> list = list(new QueryWrapper<ViewDatasourceEntity>()
                .eq("db_id", dbId));
        return list;
    }

    @Override
    public Boolean saveOrUpdateViewDataSourceList(Long viewId, List<ViewDatasourceEntity> viewDatasourceEntityList) {
        remove(new QueryWrapper<ViewDatasourceEntity>().eq("view_id", viewId));
        saveBatch(viewDatasourceEntityList);
        return true;
    }

    @Override
    public Boolean removeByViewId(Long viewId) {
        return remove(new QueryWrapper<ViewDatasourceEntity>().eq("view_id", viewId));
    }

    @Override
    public List<ViewDatasourceEntity> queryByViewId(Long viewId) {
        return list(new QueryWrapper<ViewDatasourceEntity>().eq("view_id", viewId));
    }

    @Override
    public boolean removeByProjectId(List<Long> projectIds) {
        return remove(new QueryWrapper<ViewDatasourceEntity>().in("project_id", projectIds));
    }

}